import request from '../../utils/request'

/**
 * 景点相关API接口
 */

export interface Spot {
  id: string
  name: string
  imageUrl: string
  category: string
  address: string
  longitude: number
  latitude: number
  description: string
  tags: string[]
  ticketPrice: number
  contactPhone: string
  openingHours: string
  status: 'active' | 'inactive'
  createTime: string
}

export interface SpotListParams {
  keyword?: string
  category?: string
  status?: 'active' | 'inactive' | 'all'
  page?: number
  pageSize?: number
}

export interface SpotFormData {
  id?: string
  name: string
  imageUrl: string
  category: string
  address: string
  longitude: number
  latitude: number
  description: string
  tags: string[]
  ticketPrice: number
  contactPhone?: string
  openingHours?: string
  status: 'active' | 'inactive'
}

/**
 * 获取景点列表
 */
export function getSpots(params: SpotListParams = {}) {
  return request<Spot[]>({
    url: '/spots',
    method: 'GET',
    params
  })
}

/**
 * 获取景点详情
 */
export function getSpotDetail(id: string) {
  return request<Spot>({
    url: `/spots/${id}`,
    method: 'GET'
  })
}

/**
 * 创建景点
 */
export function createSpot(data: SpotFormData) {
  return request<Spot>({
    url: '/spots',
    method: 'POST',
    data
  })
}

/**
 * 更新景点
 */
export function updateSpot(id: string, data: Partial<SpotFormData>) {
  return request<Spot>({
    url: `/spots/${id}`,
    method: 'PUT',
    data
  })
}

/**
 * 删除景点
 */
export function deleteSpot(id: string) {
  return request<null>({
    url: `/spots/${id}`,
    method: 'DELETE'
  })
}

/**
 * 更新景点状态
 */
export function updateSpotStatus(id: string, status: 'active' | 'inactive') {
  return request<Spot>({
    url: `/spots/${id}/status`,
    method: 'PATCH',
    data: { status }
  })
}

/**
 * 上传景点图片
 */
export function uploadSpotImage(data: FormData) {
  return request<{ url: string }>({
    url: '/upload/spot',
    method: 'POST',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data
  })
}

/**
 * 获取景点分类列表
 */
export function getSpotCategories() {
  return request<Array<{value: string, label: string}>>({
    url: '/spots/categories',
    method: 'GET'
  })
} 